package com.hrt.datasender.dataschedule;

import org.quartz.JobExecutionContext;

import com.btcode.common.MyLog;
import com.btcode.log.ILog;
import com.btcode.schedule.SingleInstanceJob;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.hrt.datasender.web.dataMaintain.BcConfigStorageModel;
import com.hrt.datasender.web.dataMaintain.DataMaintainService;

/**
 * 
 * 配置存储定期发送
 * 
 */
public class ConfigStorageUploadScheduler extends SingleInstanceJob {

    private ILog log;

    @Override
    public void initJob(JobExecutionContext arg0) {

        log = MyLog.getInstance().getLogger(getClass());
    }

    @Override
    public void myExecute(JobExecutionContext arg0) {
        BcConfigStorageModel model = DataMaintainService.getInstance().getModel();
        String siteCode = model.getSiteCode();
        if(siteCode!=null&&!"".equals(siteCode)) {
            String ret;
            try {
                ret = DataMaintainService.getInstance().uploadConfig(siteCode);
                JsonObject result = new JsonParser().parse(ret).getAsJsonObject();
                String resultFlag = result.get("result_flag").getAsString(); 
                String resultFlagDsc = result.get("result_flag_dsc").getAsString(); 
                if(!"SUCCESS".equals(resultFlag)) {
                    log.error("上传配置失败"+resultFlagDsc);
                }
                else {
                    log.info("配置上传成功，siteCode:" + siteCode);
                }
            }
            catch (Exception e) {
                log.error(e);
            } 
        }
    }
}
